package daobeauty.interceptor.invoke.fill;

import java.util.Map;

import org.hibernate.Query;

/**
 * Fills the named parameters of a query from a map, which is the first parameter.
 * 
 * @author M.Serhat Cinar
 *
 */
public class MapQueryFill implements ParameterFillStrategy {

	@SuppressWarnings("unchecked")
	public void fillParameters(Object q, Object[] parameters) {
		final Query query = (Query) q;
		final Map<String, Object> valuesByPropertyName = (Map<String, Object>) parameters[0];
		for (String propertyName:valuesByPropertyName.keySet()){
			query.setParameter(propertyName, valuesByPropertyName.get(propertyName));
		}
	}

	public String toString(){
		return "map";
	}

}
